package week08.horizontal;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.List;

/**
 * @author edward
 * @since 2021-08-14
 */
public class Main {
    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext("week08.horizontal");
        UserOrderRepository repo = context.getBean("userOrderRepository", UserOrderRepository.class);
        List<UserOrder> orderList;

        inserts(repo);
        updates(repo, /*select All*/ orderList = repo.selectAll());
        deletes(repo);

        System.out.println(orderList);

        // 下面代码仅作测试
        // repo.update(568, 633359215880548353L, "Well");
        // System.out.println(repo.selectById(568, 633359215880548353L));
    }

    private static void inserts(UserOrderRepository repo) {
        for (int i=0; i < 10000; i++) {
            repo.insert(i, "Result-" + i);
        }
    }

    private static void deletes(UserOrderRepository repo) {
        for (int i=0; i < 10000; i++) {
            repo.deleteByUser(i);
        }
    }

    private static void updates(UserOrderRepository repo, List<UserOrder> list) {
        for (UserOrder order : list) {
            repo.update(order.getUserId(), order.getOrderId(), "Update-" + order.getResult());
        }
    }
}
